package com.momoc.netty.frame.config;

import com.momoc.netty.frame.session.SessionManagerAbstract;
import jakarta.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 *  清理当前实例下线后的资源销毁
 */

public class CleanClientConnectResources implements  ApplicationContextAware {
    static Logger log = LoggerFactory.getLogger(CleanClientConnectResources.class);
    ApplicationContext applicationContext;


    @PreDestroy
    public void preDestroy() throws Exception {

        try {
            log.info("run client connect resources close start");
            SessionManagerAbstract bean = applicationContext.getBean(SessionManagerAbstract.class);
            bean.clearAllUserSessionInfo();
            log.info("run client connect resources close end");
        }catch (Exception e){
            log.error("run client connect resources close error", e);
        }




    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;

    }
}